<html>
<head><meta charset="utf-8"><title>unexpectedly non-overlapping blanket implementaions · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html">unexpectedly non-overlapping blanket implementaions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="218581538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218581538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218581538">(Dec 02 2020 at 16:27)</a>:</h4>
<p>Why aren't these two impls overlapping? This works in at least Rust 1.30 / edition 2015, so it's not any recent change.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">IntoResult</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">into_result</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="n">IntoResult</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">Result</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">into_result</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="bp">self</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="n">IntoResult</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">into_result</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Ok</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="218581851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218581851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218581851">(Dec 02 2020 at 16:29)</a>:</h4>
<p>What prevents <code>T</code> in the second impl from being <code>Result&lt;T, E&gt;</code>?</p>



<a name="218581987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218581987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218581987">(Dec 02 2020 at 16:30)</a>:</h4>
<p>those are different types</p>



<a name="218582007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218582007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218582007">(Dec 02 2020 at 16:30)</a>:</h4>
<p>you'd have Result&lt;Result&lt;T, E&gt;, E&gt;</p>



<a name="218582058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218582058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218582058">(Dec 02 2020 at 16:31)</a>:</h4>
<p>I think</p>



<a name="218583542"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583542" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583542">(Dec 02 2020 at 16:41)</a>:</h4>
<p>But I could substitute <code>T = i32</code> and <code>E = ()</code> for the first impl, or <code>T = Result&lt;i32, ()&gt;</code> and <code>E = ()</code> for the second.</p>



<a name="218583583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583583">(Dec 02 2020 at 16:41)</a>:</h4>
<p>Maybe because the <code>T</code> and <code>E</code> become part of the trait's types</p>



<a name="218583692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583692">(Dec 02 2020 at 16:42)</a>:</h4>
<p>you would still return <code>Result&lt;Result&lt;i32, ()&gt;, ()&gt;</code> in the second example though</p>



<a name="218583722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583722">(Dec 02 2020 at 16:42)</a>:</h4>
<p>you can implement both <code>Trait&lt;A&gt;</code> and <code>Trait&lt;B&gt;</code> for the same type</p>



<a name="218583725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583725">(Dec 02 2020 at 16:42)</a>:</h4>
<p>so there's never the same impl _of the trait_ for the type</p>



<a name="218583742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583742">(Dec 02 2020 at 16:42)</a>:</h4>
<p>as long as <code>A</code> and <code>B</code> are not overlapping</p>



<a name="218583745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583745">(Dec 02 2020 at 16:42)</a>:</h4>
<p>Yeah, <code>IntoResult&lt;Result&lt;i32, ()&gt;, ()&gt;</code> is a different trait than <code>IntoResult&lt;i32, ()&gt;</code></p>



<a name="218583755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583755">(Dec 02 2020 at 16:42)</a>:</h4>
<p>these are <em>different</em> T's and E's, they're scoped</p>



<a name="218583848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583848">(Dec 02 2020 at 16:43)</a>:</h4>
<p>You may want those parameters to be associated types instead since they're semantically outputs of the trait's method</p>



<a name="218583900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583900">(Dec 02 2020 at 16:43)</a>:</h4>
<p>And </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">IntoResult</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">into_result</span><span class="p">(</span><span class="bp">self</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="n">IntoResult</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="nb">Result</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">E</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">into_result</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">IntoResult</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">into_result</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>fails because it's the same trait.</p>



<a name="218583911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583911">(Dec 02 2020 at 16:43)</a>:</h4>
<p>at which point you could only have one of those impls</p>



<a name="218583976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218583976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Steven Fackler <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218583976">(Dec 02 2020 at 16:44)</a>:</h4>
<p>yeah</p>



<a name="218584038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218584038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218584038">(Dec 02 2020 at 16:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="243558">Steven Fackler</span> <a href="#narrow/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions/near/218583745">said</a>:</p>
<blockquote>
<p>Yeah, <code>IntoResult&lt;Result&lt;i32, ()&gt;, ()&gt;</code> is a different trait than <code>IntoResult&lt;i32, ()&gt;</code></p>
</blockquote>
<p>I think this is the key point that I was forgetting.</p>



<a name="218584301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/unexpectedly%20non-overlapping%20blanket%20implementaions/near/218584301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions.html#218584301">(Dec 02 2020 at 16:46)</a>:</h4>
<p><span class="user-mention silent" data-user-id="243558">Steven Fackler</span> <a href="#narrow/stream/122651-general/topic/unexpectedly.20non-overlapping.20blanket.20implementaions/near/218583848">said</a>:</p>
<blockquote>
<p>You may want those parameters to be associated types instead since they're semantically outputs of the trait's method</p>
</blockquote>
<p><em>I</em> don't want anything in this specific case <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span>. I think that <a href="https://stackoverflow.com/a/65111494/155423">the original case</a> benefits from the current behavior.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>